package com.dyg.controller.admin;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.dyg.model.Goods;
import com.dyg.service.GoodsService;

@Controller
@RequestMapping("/admin/goods")
public class GoodsController {

	@Autowired
	private GoodsService goodsService;
	
	@RequestMapping(value = "/list",method = RequestMethod.GET)
	public String list(
			Model model,
			String name){
		List<Goods> goodsList = goodsList = goodsService.list();
		
		if(!StringUtils.isEmpty(name)){
			if(goodsList != null && goodsList.size() > 0){
				
				for (Goods goods : goodsList) {
					goodsService.addDocument(goods);
				}
			}
			goodsList = goodsService.queryGoods(name);
		}
		
		model.addAttribute("goodslist",goodsList);
		
		return "goods/list";
	}
}
